﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.SqlClient;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;


namespace LANmine
{
    public partial class SeatsForm : Form
    {
        private Language lmLang;

        public SeatsForm()
        {
            InitializeComponent();
        }

        // Default constructor extension
        public SeatsForm(Language Lang) : this()
        {
            /** Save the language object */
            this.lmLang = Lang;

            /** Dock the window */
            this.Dock = DockStyle.Fill;

            ApplyLanguage();
        }


        #region Language Specifications
        /**
         * MainForm::ApplyLanguage()
         * ---------------------------
         * Overwrite all text properties of all elements in all forms with the right ones.
         */
        private void ApplyLanguage()
        {
            /**
             * Header label
             */
            this.lblSeats.Text = this.lmLang.GetString("menu.btnSeats");
        }
        #endregion


        private void LoadCoordinaten()
        {
            Database dbCoordinaten = new Database("ro");
            SqlConnection dbConn = dbCoordinaten.getDbConn();

            SqlDataAdapter daCoordinaten = new SqlDataAdapter("SELECT * From plaatsen AS p INNER JOIN deelnemers AS d ON p.deelnemer_id = d.id", dbConn);
            DataSet dsCoordinaten = new DataSet("Coordinaat");

            daCoordinaten.FillSchema(dsCoordinaten, SchemaType.Source, "Coordinaat");
            daCoordinaten.Fill(dsCoordinaten, "Coordinaat");

            DataTable dtCoordinaten;
            dtCoordinaten = dsCoordinaten.Tables["Coordinaat"];

            String x, y, naam;
            //int xx = 35;
            //int yy = 65;

            pbParent.Controls.Clear();

            foreach (DataRow drCurrent in dtCoordinaten.Rows)
            {
                x = drCurrent["x"].ToString();
                y = drCurrent["y"].ToString();
                naam = drCurrent["gebruikersnaam"].ToString();

                // Instantieer Seat
                // Seat seatCtrl = new Seat(naam);
                
                // Positie instellen
                // seatCtrl.Location = new Point(Convert.ToInt32(x), Convert.ToInt32(y));
                // kijken of deelnemer er al is
                Boolean positie = Convert.ToBoolean(drCurrent["positie"].ToString());
                if (positie == true)
                {
                    SeatV seatVCtrl = new SeatV(naam);
                    seatVCtrl.Location = new Point(Convert.ToInt32(x), Convert.ToInt32(y));
                    Boolean checkedin = Convert.ToBoolean(drCurrent["checkedin"].ToString());
                    if (checkedin == true)
                    {
                        //MessageBox.Show(drCurrent["voornaam"].ToString());
                        seatVCtrl.lblNaam.BackColor = System.Drawing.Color.Green;
                    }
                    pbParent.Controls.Add(seatVCtrl);
                }
                else
                {
                    Seat seatCtrl = new Seat(naam);
                    seatCtrl.Location = new Point(Convert.ToInt32(x), Convert.ToInt32(y));
                    Boolean checkedin = Convert.ToBoolean(drCurrent["checkedin"].ToString());
                    if (checkedin == true)
                    {
                        //MessageBox.Show(drCurrent["voornaam"].ToString());
                        seatCtrl.lblNaam.BackColor = System.Drawing.Color.Green;

                    }
                    pbParent.Controls.Add(seatCtrl);
                }
                
                // Seat toevoegen
                
            }
        }

        private void SeatsForm_Activated(object sender, EventArgs e)
        {
            LoadCoordinaten();
        }
    }
}
